﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using FarseerPhysics.Collision;
using FarseerPhysics.Collision.Shapes;
using Somnus.Utils;
using Somnus.Core;

namespace Somnus.Objects.GameObjects.Characters
{
    class Voador : Character
    {
         #region Variaveis Privadas
        private float spawnPointX, spawnPointY,flyingRangeX,flyingRangeY, flyingVelocityX, flyingVelocityY; 

        private Vector2 position;
		
        #endregion

		public Voador(DreamWorld world, String name, Texture2D texture, Nullable<Rectangle> sourceRectangle, float depth, Boolean isStatic, float x, float y, float width, float height, float rotation)
            : base(world, name, texture, sourceRectangle, depth, isStatic, x, y, width, height, rotation)
		{
            
            flyingRangeX = 100;
            flyingRangeY = 20;
            flyingVelocityX = 0.5f;
            flyingVelocityY = 0.5f;
			flyingVelocityX = flyingVelocityX / 20;
			flyingVelocityY = flyingVelocityY / 20;
            this.body.IgnoreCCD = true;
            this.body.IgnoreGravity = true;

            this.body.IgnoreCCD = true;
            this.body.IgnoreGravity = true;

            this.art.inverted = true;
			position = new Vector2(x / 20, y / 20);
			
			spawnPointX = x / 20;
			spawnPointY = y / 20;
			
		}
		
		public override void update(GameTime gameTime)
		{
			flyingRangeX = this.body.Position.X - spawnPointX;			
			flyingRangeY = this.body.Position.Y - spawnPointY;

			//flyingVelocityY = 0.5 - flyingRangeY;
			//trace (flyingVelocityY)
			
			if (Math.Abs(flyingRangeX) > 1.5)
			{
				flyingVelocityX *= -1;
                if (this.art.inverted == true)
                {
                    this.art.inverted = false;
                }
                else
                {
                    this.art.inverted = true;
                }
			}

           
			
			if (flyingRangeY > 0)
			{
				flyingVelocityY += 0.001f;
			}
			
			else
			{
                flyingVelocityY -= 0.001f;
			}
			
			
			position.X += flyingVelocityX;
			position.Y -= flyingVelocityY;
            this.body.Position = position;

           
			base.update(gameTime);
			
		}
    }
}
